package com.example.runningman.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.runningman.R;
import com.example.runningman.bean.BaiduPoints;
import com.example.runningman.bean.Liked;
import com.example.runningman.friend.FriendActivity;
import com.example.runningman.util.SPUtil;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import androidx.recyclerview.widget.RecyclerView;

public class Run_adapter extends RecyclerView.Adapter<Run_adapter.ViewHolder> {
    List<BaiduPoints> mData;
    Activity mActivity;
    RequestOptions options;
    String useid;
    boolean f =false;
    public Run_adapter(List<BaiduPoints> data, Activity activity) {
        this.mData = data;

        this.mActivity = activity;
        useid= SPUtil.getInstance(mActivity).getString("useid");
        options = new RequestOptions()
                .placeholder(R.mipmap.ic_launcher)
                .override(80,80)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.NONE);
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v;

        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_run, parent, false);



        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(Run_adapter.ViewHolder holder, int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(v, position);
                }
            }
        });
        holder.run_content.setText(mData.get(position).getTime());

    }



    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public void refresh(List<BaiduPoints> data){
        this.mData = data;
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView run_content;


        public ViewHolder(View itemView) {
            super(itemView);

            run_content = itemView.findViewById(R.id.run_content);



        }
    }
    //私有属性
    private OnItemClickListener onItemClickListener = null;

    //setter方法
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    //回调接口
    public interface OnItemClickListener {
        void onItemClick(View v,  int position);
    }

}